package com.tpp.service.impl;

import com.tpp.service.InformationService;
import com.tpp.utils.CodeUtils;
import com.tpp.utils.RedisUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class InformationServiceImpl implements InformationService {


    static String verifyCode=null;
    @Autowired
    RedisUtils redisUtils;
    @RabbitListener(queues = "tpp-cloud-information")

    public void getCode(Map map) {
//        1.获取从前端传来的手机号
        Object phone = map.get("phone");
        System.out.println(phone.toString());

        //2.获取验证码
        verifyCode = CodeUtils.getCodeDx(phone.toString());
        System.out.println(verifyCode);
        if(phone!=null&&phone!=""){

            //3.如果发送成功，记录到redis中
            redisUtils.set(phone.toString(),verifyCode);

            //4.设置5分钟过期时间
            redisUtils.expire(phone.toString(),300);

        }else{

        }
    }
}
